{% extends "one_column.html" %}

{% block title %} Experiment Details {% endblock %}

{% block first_column %}
  {% if has_access %}
    <h1> {{ experiment.name }}: Experiment Details </h1>
    <ul>
      <li> Name: {{ experiment.name }}
      <li> Description: {{ experiment.description }}
      <li> Participant Instructions: {{ experiment.instructions|safe }}
      <li> Device: {{ experiment.device }}
      <li> Owner:
        <a href="mailto:{{ experiment.owner }}@google.com">{{ experiment.owner }}</a>
      <li> Type: {{ experiment.experiment_type }}
      <li> Created: {{ experiment.created }}
      <li> Participant URL:
        <a href="{{ experiment_url }}"> {{ experiment_url }} </a>
      <li> Treatments:
        {% for treatment in treatments %}
          <div class="rectangle">
            <h2> {{ treatment.name }} </h2>
            <ul>
              {% for property in properties %}
                {% if property.parent_key() == treatment.key() %}
                  <li> {{ property.name }} = {{ property.value }}
                {% endif %}
              {% endfor %}
            </ul>
          </div>
        {% endfor %}
    </ul>

    <h1> Results </h1>
    <p> <a href="csv?exp_key={{ experiment.key() }}">Download csv</a> </p>

    {% if experiment.participants %}
      <table>
        <tr class="even_row"><th>Participant</th>
          {% for treatment in treatments %}
            <th> {{ treatment.name }} </th>
          {% endfor %}
        </tr>

        {% for participant in experiment.participants %}
          <tr class="{{ loop.index|row_class }}">
            <td> <a href="mailto:{{ participant }}@google.com">{{ participant }}</a> </td>
            {% set participant_number = loop.index0 %}
            {% for treatment in treatments %}
              <td class="score">
                {{ treatment.scores[participant_number] }}
              </td>
            {% endfor %}
            <td>
              {{ experiment.feedback[loop.index0] }}
            </td>
          </tr>
        {% endfor %}

        <tr>
          <th> Average: </th>
          {% for treatment in treatments %}
            <th> {{ treatment.scores|average}} </th>
          {% endfor %}
        </tr>

        <tr>
          <th> Variance: </th>
          {% for treatment in treatments %}
            <th> {{ treatment.scores|variance}} </th>
          {% endfor %}
        </tr>
      </table>

      <h2> Sign-test P Values</h2>
      <p>
        The Rows indicate the treatment in question and the columns
        are the treatments they are being compared to.  A low p value
        indicates that the row treatment is likely <b>better</b> than
        the column treatment.
      </p>
      <table>
        <tr> <th> -- </th>
          {% for treatment in treatments %}
            <th> {{ treatment.name }} </th>
          {% endfor %}
        </tr>

        {% for t1 in treatments %}
          <tr class="{{ loop.index|row_class }}">
            <th> {{ t1.name }} </th>
            {% for t2 in treatments %}
              <td class="score">
                {% if t1.name != t2.name %}
                  {{ t1.scores|sign_test(t2.scores) }}
                {% endif %}
              </td>
            {% endfor %}
          </tr>
        {% endfor %}
      </table>
    {% else %}
      <p>
        No one has completed this experiment yet, there are no results to
        display.
      </p>
    {% endif %}
  {% else %}
    <h1> Permission Denied </h1>
    <p>
      Sorry, but you are neither the owner of this experiment nor an
      administrator, please contact the owner
      (<a href="mailto:{{ experiment.owner }}@google.com"> {{ experiment.owner }}</a>)
      directly for details about this experiment.
    </p>
  {% endif %}
{% endblock %}
